package com.glory.brepda.adapter;

import android.app.AlertDialog;
import android.content.Context;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.brepda.R;
import com.glory.brepda.entity.MultiEqpBean;

import java.util.List;

public class EqpIDLEAdapter extends BaseQuickAdapter<MultiEqpBean, BaseViewHolder> {


    Context context;
    private OnItemClickListener onItemClickListener;
    public EqpIDLEAdapter(@Nullable List<MultiEqpBean> data, Context context) {
        super(R.layout.adapter_eqpidle, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiEqpBean s) {
        helper.setText(R.id.tveqpid,s.getEQUIPMENTID());
        helper.getView(R.id.delete).setOnClickListener(view -> {
            // 创建一个AlertDialog.builder对象
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle("确认删除");
            builder.setMessage("你确定要删除这条记录吗？");
            builder.setPositiveButton("确定", (dialog, which) -> {
                if ( onItemClickListener != null) {
                    onItemClickListener.onItemClick(this, view, helper.getAdapterPosition());
                }
            });
            builder.setNegativeButton("取消", (dialog, which) -> {
                // 用户点击了取消按钮，不做任何事情
                dialog.dismiss();
            });

            // 显示弹窗
            AlertDialog dialog = builder.create();
            dialog.show();
        });
    }

    @Override
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
}
